package com.framework.yhbapi.controller;


import com.framework.exception.util.RespResult;
import com.framework.service.yhbservice.YhbUserOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * 功能描述: 支付宝支付
 *
 * @author ck
 * @date 2018/9/19 15:45
 */
@RestController
@RequestMapping(value = "yhbPay")
@Api(value="支付宝支付模块",tags={"支付宝支付模块"})
public class AliPayController {


	@Autowired
	private YhbUserOrderService yhbUserOrderService;

	/**
	 * 支付操作
	 * @param token 当前人登陆人token
	 * @param body
	 * @param subject
	 * @param orderNo
	 * @param totalAmount
	 * @param password
	 * @return
	 */
	@PostMapping("pay")
	@ApiOperation("支付操作")
	@ApiImplicitParams({
			@ApiImplicitParam(name="body",value="订单的具体描述",dataType="String", paramType = "query",required = true),
			@ApiImplicitParam(name="subject",value="商品标题",dataType="String", paramType = "query" ,required = true),
			@ApiImplicitParam(name="orderNo",value="订单号",dataType="String", paramType = "query",required = true ),
			@ApiImplicitParam(name="totalAmount",value="支付金额",dataType="BigDecimal", paramType = "query" ,required = true),
			@ApiImplicitParam(name="payType",value="支付方式 1：余额支付  2：支付宝",dataType="int", paramType = "query",required = true ),
			@ApiImplicitParam(name="password",value="交易密码",dataType="String", paramType = "query",required = true )
	})
	public RespResult pay(String token,String body,String subject,String orderNo,BigDecimal totalAmount,Integer payType,String password){
		String res = yhbUserOrderService.pay(token,body,subject,orderNo,totalAmount,payType,password);
		return RespResult.ok().put("res",res);
	}


	/**
	 * 支付操作

	 * @param body
	 * @param subject
	 * @param orderNo
	 * @param totalAmount

	 * @return
	 */
	@PostMapping("payByPhone")
	@ApiOperation("支付操作")
	@ApiImplicitParams({
			@ApiImplicitParam(name="deptId",value="渠道id",dataType="Long", paramType = "query",required = true),
			@ApiImplicitParam(name="body",value="订单的具体描述",dataType="String", paramType = "query",required = true),
			@ApiImplicitParam(name="subject",value="商品标题",dataType="String", paramType = "query" ,required = true),
			@ApiImplicitParam(name="orderNo",value="订单号",dataType="String", paramType = "query",required = true ),
			@ApiImplicitParam(name="totalAmount",value="支付金额",dataType="BigDecimal", paramType = "query" ,required = true),
			@ApiImplicitParam(name="payType",value="支付方式 1：余额支付  2：支付宝",dataType="int", paramType = "query",required = true )

	})
	public RespResult payByPhone(Long deptId,String body,String subject,String orderNo,BigDecimal totalAmount,Integer payType,String phone){
		String res = yhbUserOrderService.payByPhone(deptId,body,subject,orderNo,totalAmount,payType,phone);
		return RespResult.ok().put("res",res);
	}
}
